<template>
  <div class="app-container">
    <!-- 体验券详情 -->
    <h5 class="titleInfo">体验券详情</h5>
    <!-- 查询模块 -->
    <el-form ref="form" :model="form" label-width="100px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="批次号">
            <span class="spanToInput">{{ form.code }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="有效期">
            <span class="spanToInput">{{ form.start_time + ' 至 ' + form.end_time }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="已领取数量">
            <span class="spanToInput">{{ form.saveCount }}张</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="体验券名称">
            <span class="spanToInput">{{ form.name }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="服务名称">
            <span class="spanToInput">{{ form.service_name }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="已使用数量">
            <span class="spanToInput">{{ form.useCount }}张</span>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div v-loading="tableLoading" class="listDiv">
      <el-table :data="tableData" style="width: 100">
        <el-table-column fixed label="序号" type="index" width="80" />
        <el-table-column prop="code" label="体验券编码" />
        <el-table-column prop="order_sn" label="使用订单号" />
        <el-table-column prop="phone" label="用户手机号" />
        <el-table-column prop="status" label="状态" />
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.pageNum"
            :page-sizes="page_sizes"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { detailInfo, detailTableInfo } from '@/api/couponsList'

export default {
  data() {
    return {
      form: {},
      tableLoading: false,
      tableData: [],
      page_sizes: [10, 30, 50, 100], // 每页显示个数
      page_totals: 60, // 总条目数,
      form1: {
        page: 1,
        pageSize: 10,
        id: ''
      },
      id: ''
    }
  },
  created() {
    const id = this.$route.query.id
    this.id = id
    this.form1.id = id
    this.getList(id)
  },
  methods: {
    // 数据获取
    getList() {
      this.tableLoading = true
      detailInfo({ id: this.id })
        .then(res => {
          if (res.data.code == 200) {
            // console.log(res)
            this.form = res.data.data
            // this.page_totals = res.data.data.total;
            // this.tableLoading =false
          } else {
            this.$message.error(res.data.msg)
          }
        })
        .catch(error => {
          this.$message.error(error)
        })
      detailTableInfo(this.form1).then(res => {
        if (res.data.code == 200) {
          // console.log(res)
          this.tableData = res.data.data.data
          this.page_totals = res.data.data.total
          this.tableLoading = false
        } else {
          this.$message.error(res.data.msg)
        }
      }).catch(error => {
        this.$message.error(error)
      })
    },

    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val
      this.getList()
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val
      this.getList()
    }
  }
}
</script>
<style scoped>
.app-container {
    padding: 0.1px !important;
}
.form {
    margin-left: 20px;
}
.listDiv {
    padding-bottom: 20px;
    margin: 0 20px;
    box-sizing: border-box;
}
</style>
